﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
public partial class Reportes_ArchivosReportes_ReporteSuspensiones : System.Web.UI.Page
{
    private  const string NullTextValue="- -";
    private  ReportData reportData = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            this.ddlDiaInicio.Items.Add(NullTextValue);
            this.ddlDiaFin.Items.Add(NullTextValue);
            for (short i = 1; i <= 31; i++)
            {
                this.ddlDiaInicio.Items.Add(i.ToString());
                this.ddlDiaFin.Items.Add(i.ToString());
            }
            ddlMesInicio.Items.Add(NullTextValue);
            ddlMesFin.Items.Add(NullTextValue);
            for (short i = 1; i <= 12; i++)
            {
                ddlMesInicio.Items.Add(i.ToString());
                ddlMesFin.Items.Add(i.ToString());
            }

            ddlAnhoInicio.Items.Add(NullTextValue);
            ddlAnhoFin.Items.Add(NullTextValue);

            for (short i = 2008; i <= 2018; i++)
            {
                ddlAnhoInicio.Items.Add(i.ToString());
                ddlAnhoFin.Items.Add(i.ToString());
            }
        }
        Session.Clear();

    }
    
    protected void btnConsultar_Click(object sender, EventArgs e)
    {
        /*Session.Clear();
        string select = BuildSelectSentence();
        reportData = new ReportData();

        reportData.ReportPath = MapPath(@"ArchivosReportes/ReporteMotivoSuspension.rpt");
        reportData.ReportSelect = select;
        reportData.TableName = "vw_ReporteSuspensiones";
        Session[ReportData.SessionReportDataKey] = reportData;
        Session["Titulo"] = "Reporte de suspensiones del servicio en ventanillas";
        Response.Redirect(@"~\Reportes\Common\VisualizadorReportes.aspx");*/
    }
    /*
    protected string BuildSelectSentence()
    {
        
        SelectSentenceBuilder select = new SelectSentenceBuilder("vw_ReporteSuspensiones");
        if (!IsNullValue(ddlMotivoSuspension)) 
            select.AddAndFilter(new WhereFilter("nombre",ddlMotivoSuspension.Items[ddlMotivoSuspension.SelectedIndex].Text,WhereFilter.WhereOperation.Like,WhereFilter.SQLValueType.String));
        if (!IsNullValue(ddlVentanilla))
            select.AddAndFilter(new WhereFilter("ventanilla", ddlVentanilla.Text, WhereFilter.WhereOperation.Equal, WhereFilter.SQLValueType.Integer));

        DateTime? dti=GetDateFromDownDropLists(ddlDiaInicio,ddlMesInicio, ddlAnhoInicio);
        DateTime? dtf=GetDateFromDownDropLists(ddlDiaFin, ddlMesFin, ddlAnhoFin);

        if (dti != null)
        {
            select.AddAndFilter(new WhereFilter("fecha", dti.Value.ToShortDateString(), WhereFilter.WhereOperation.MoreEqualThan, WhereFilter.SQLValueType.String)); ;
            Session["Fecha_ini"] = dti.Value.ToShortDateString();
        }
        else Session["Fecha_ini"] = "- -";

        if (dtf != null)
        {
            select.AddAndFilter(new WhereFilter("fecha", dtf.Value.ToShortDateString(), WhereFilter.WhereOperation.LessEqualThan, WhereFilter.SQLValueType.String)); ;
            Session["Fecha_fin"] = dti.Value.ToShortDateString();
        }
        else Session["Fecha_fin"] = "- -";

        select.Build();

       return select.GetBuiltSelect();
    }*/


    private  DateTime? GetDateFromDownDropLists(DropDownList day, DropDownList month, DropDownList year)
    {
        
        string stringdate = day.Text + '/' + month.Text + '/' + year.Text;
        DateTime dateTime = new DateTime();
        if (DateTime.TryParse(stringdate, out dateTime))
        {
            return dateTime;
        }
        else return null;
    }

    private bool IsNullValue(object value)
    {
        if (value is DropDownList) return ((DropDownList)value).Text == NullTextValue;
        if (value is TextBox) return ((TextBox)value).Text == NullTextValue;
        return true;
    }

    protected void AddNullValue(object sender, EventArgs e)
    {
        DropDownList list = (DropDownList)sender;

        list.Items.Insert(0, NullTextValue);
    }


   
}
